package;

import openfl.display.Sprite;
import openfl.events.KeyboardEvent;
import visual.*;
import common.Main;
import common.Constants.*;

class App extends Sprite {
    var grid: Grid;
    var loop: Main;

    var keys = [
        // Esc
        27 => KEY_EXIT,

        // qwe
        // a d
        // zsx
        81 => KEY_UPLEFT,
        87 => KEY_UP,
        69 => KEY_UPRIGHT, // nice
        65 => KEY_LEFT,
        68 => KEY_RIGHT,
        90 => KEY_DOWNLEFT,
        83 => KEY_DOWN,
        88 => KEY_DOWNRIGHT,
    ];

    public function new() {
        super();

        grid = new Grid();
        addChild(grid);

        loop = new Main(grid);

        stage.addEventListener(KeyboardEvent.KEY_DOWN, keyUp);
    }

    function keyUp(evt: KeyboardEvent) {
        loop.update(keys[evt.keyCode]);
    }
}
